<%@ page language="java" contentType="text/html; charset=windows-1256"
    pageEncoding="windows-1256"%>
<%
//is the user allowed to be here?
if(!fr.upmc.utils.SessionTracker.isUserConnected(request))
{
	fr.upmc.utils.SessionTracker.redirectToHome(response);
	return;
}

org.hibernate.Session s = fr.upmc.utils.HibernateUtils.getSessionFactory().openSession();
long id = -1;
try{
	id = Long.parseLong(request.getParameter("id"));
}
catch(Exception e){}

fr.upmc.dao.ContactDAO dao = new fr.upmc.dao.ContactDAO(s);
java.util.List<fr.upmc.bean.Contact> contacts = dao.getAllContacts();

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="scripts/login/css/style.css" />
    <script src="scripts/jquery/js/jquery-1.6.2.min.js"></script>
    <script src="scripts/jquery/js/jquery-ui-1.8.16.custom.min.js"></script>
    <script src="scripts/customInput.jquery.js"></script>
    <script src="scripts/login/js/login.js"></script>
    <script src="scripts/jquery/jquery.validate.js"></script>
    <link rel="stylesheet" href="scripts/jquery/css/ui-darkness/jquery-ui-1.8.16.custom.css" />
    <link rel="stylesheet" href="scripts/customInput.css" />
<title>All contact</title>

<style type="text/css">
table
{
    border-style: solid;
    border-width: 2px;
}

td
{
    border-top: thin solid black; 
}
</style>

<script type="text/javascript">
$(document).ready(function(){
    var button = $('#logoutButton');
    var form = $('#logoutForm');
    
    button.click(function(){
    	if(confirm('Are you sure you want to logout?'))
    		form.submit();
    	else
    		return;
    });
    
    $('input:submit').button();
    $('input').customInput();
});
</script>
</head>
<body>
<div id="bar">
        <div id="container">
            <!-- Login Starts Here -->
            <div id="title">MDOC Project - List Contacts</div>
            <div id="loginContainer">
            	<a href="accueil.jsp" id="home">Home</a>
                <a href="#" id="logoutButton"><span>Log out</span></a>
                <div style="clear:both"></div>
                <div id="loginBox">                
                    <form id="logoutForm" action="authentification.do" method="post">
                        <fieldset id="body">
                            <input type="hidden" name="action" value="logout" >
                            <input type="submit" id="logout" value="Sign out" />
                        </fieldset>
                    </form>
                </div>
            </div>
            <!-- Login Ends Here -->
		</div>
	</div>
	
<div class="container">
	<br/>
	<%if(contacts == null){%>
		<i><h3>No contacts found</h3></i>.
	<%}else{%>
	<center><table cellpadding="10" cellspacing="0">
	<tr>
		<th></th>
		<th></th>
		<th></th>
		<th>First name</th>
		<th>Last name</th>
		<th>Email</th>
	</tr>
	<%
		int i = 0;
		for(i = 0; i < contacts.size(); i++){%>
			<tr>
				<td><b><a href="contactDetails.jsp?id=<%=contacts.get(i).getContactId()%>">Details</a></b></td>
				<td><b><a href="updateContact.jsp?id=<%=contacts.get(i).getContactId()%>">Update</a></b></td>
				<td><b><a href="deleteContact.jsp?id=<%=contacts.get(i).getContactId()%>">Delete</a></b></td>
				<td><%=contacts.get(i).getFirstName() %></td>
				<td><%=contacts.get(i).getLastName() %></td>
				<td><%=contacts.get(i).getEmail() %></td>
			</tr>
		<% }	%>
	</table></center>
	<%} %>
</div>
</body>
</html>